Allows to automate task submission to a set of threads. More...
Public Member Functions | |
Scheduler (size_t threadCount=0) | |
~Scheduler () | |
size_t | getThreadCount () const |
Thread * | getThread (size_t index) const |
void | addTask (Task *task) |
void | resolveTask (Task *task) |
void | checkEndedTasks () |
void | joinAllThreads () |
void | resizeForThreadCount (size_t threadCount) |
Allows to automate task submission to a set of threads.
Aim is to schedule work and let it be distributed as smoothly as possible.
nkTasks::Scheduler::Scheduler | ( | size_t | threadCount = 0 | ) |
Constructor.
threadCount | The number of thread wanted to populate the scheduler's pool. If 0, the scheduler will choose a plausible thead count itself. |
nkTasks::Scheduler::~Scheduler | ( | ) |
Destructor.
size_t nkTasks::Scheduler::getThreadCount | ( | ) | const |
Thread* nkTasks::Scheduler::getThread | ( | size_t | index | ) | const |
index | The index in the pool of wanted thread. |
void nkTasks::Scheduler::addTask | ( | Task * | task | ) |
Submit a task to the scheduler.
task | Task to submit. |
void nkTasks::Scheduler::resolveTask | ( | Task * | task | ) |
Allows to mark a task as resolved and trigger its post execution callbacks.
task | The task to resolve. |
void nkTasks::Scheduler::checkEndedTasks | ( | ) |
Ticking function for execution. This should be called within the main thread, the one owning the scheduler and submitting work. Once a thread has finished processing a task, it will mark it as resolved and enqueue it for resolving within the scheduler. This function has to be called to fully resolve tasks that have been marked as resolved from the work thread.
void nkTasks::Scheduler::joinAllThreads | ( | ) |
Allows to join all threads of the scheduler.
void nkTasks::Scheduler::resizeForThreadCount | ( | size_t | threadCount | ) |
Allows to change the number of threads constituting this scheduler's thread pool.
threadCount | The number of threads that should constitute the pool. |